<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="&amp;#x524D;&amp;#x8A00; &amp;#x4E4B;&amp;#x524D;&amp;#x4E00;&amp;#x76F4;&amp;#x60F3;&amp;#x5BF9;OpenCV&amp;#x8FDB;&amp;#x884C;&amp;#x5B66;&amp;#x4E60;&amp;#x548C;&amp;#x4F7F;&amp;#x7528;&amp;#xFF0C;&amp;#x4E00;&amp;#x76F4;&amp;#x6CA1;&amp;#x6709;&amp;#x5B9E;&amp;#x8DF5;&amp;#x3002;&amp;#x8FD9;&amp;">
<meta property="og:type" content="article">
<meta property="og:title" content="Android studio 3.0配置OpenCV初探">
<meta property="og:url" content="http://yoursite.com/2019/08/21/Android-studio-3.0配置OpenCV初探/index.html">
<meta property="og:site_name" content="Silence潇湘夜雨">
<meta property="og:description" content="&amp;#x524D;&amp;#x8A00; &amp;#x4E4B;&amp;#x524D;&amp;#x4E00;&amp;#x76F4;&amp;#x60F3;&amp;#x5BF9;OpenCV&amp;#x8FDB;&amp;#x884C;&amp;#x5B66;&amp;#x4E60;&amp;#x548C;&amp;#x4F7F;&amp;#x7528;&amp;#xFF0C;&amp;#x4E00;&amp;#x76F4;&amp;#x6CA1;&amp;#x6709;&amp;#x5B9E;&amp;#x8DF5;&amp;#x3002;&amp;#x8FD9;&amp;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1716569-f3db8a0991ccb129.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1716569-3f43cc05dac1b245.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1716569-eea5e8241e3995fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1716569-1d4ceece061a91f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1716569-b43e1f03a33a4539.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2019-07-19T05:32:38.996Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android studio 3.0配置OpenCV初探">
<meta name="twitter:description" content="&amp;#x524D;&amp;#x8A00; &amp;#x4E4B;&amp;#x524D;&amp;#x4E00;&amp;#x76F4;&amp;#x60F3;&amp;#x5BF9;OpenCV&amp;#x8FDB;&amp;#x884C;&amp;#x5B66;&amp;#x4E60;&amp;#x548C;&amp;#x4F7F;&amp;#x7528;&amp;#xFF0C;&amp;#x4E00;&amp;#x76F4;&amp;#x6CA1;&amp;#x6709;&amp;#x5B9E;&amp;#x8DF5;&amp;#x3002;&amp;#x8FD9;&amp;">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/1716569-f3db8a0991ccb129.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/08/21/Android-studio-3.0配置OpenCV初探/">





  <title>Android studio 3.0配置OpenCV初探 | Silence潇湘夜雨</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Silence潇湘夜雨</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Android开发一枚</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home //首页"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user //关于"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags  //标签"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th //分类"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive //归档"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar //日程表"></i> <br>
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap //站点地图"></i> <br>
            
            站点地图
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/21/Android-studio-3.0配置OpenCV初探/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Silence潇湘夜雨">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Silence潇湘夜雨">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android studio 3.0配置OpenCV初探</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-08-21T15:51:43+08:00">
                2019-08-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/openCV/" itemprop="url" rel="index">
                    <span itemprop="name">openCV</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.5k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  9
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="&#x524D;&#x8A00;"><a href="#&#x524D;&#x8A00;" class="headerlink" title="&#x524D;&#x8A00;"></a>&#x524D;&#x8A00;</h2><p> &#x4E4B;&#x524D;&#x4E00;&#x76F4;&#x60F3;&#x5BF9;OpenCV&#x8FDB;&#x884C;&#x5B66;&#x4E60;&#x548C;&#x4F7F;&#x7528;&#xFF0C;&#x4E00;&#x76F4;&#x6CA1;&#x6709;&#x5B9E;&#x8DF5;&#x3002;&#x8FD9;&#x6B21;&#x75DB;&#x4E0B;&#x51B3;&#x5FC3;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x641E;&#x5B9A;&#x3002;&#x7ECF;&#x8FC7;&#x4E24;&#x5929;&#x7684;&#x6298;&#x817E;&#xFF0C;&#x9047;&#x5230;&#x5404;&#x79CD;bug&#x7EC8;&#x4E8E;&#x641E;&#x5B9A;&#x4E86;&#xFF0C;&#x5E0C;&#x671B;&#x80FD;&#x5E2E;&#x52A9;&#x5230;&#x521D;&#x5B66;&#x8005;&#xFF0C;&#x5982;&#x679C;&#x91CC;&#x9762;&#x6709;&#x90A3;&#x4E9B;&#x5199;&#x7684;&#x4E0D;&#x5BF9;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x8FD8;&#x5E0C;&#x671B;&#x5404;&#x4F4D;&#x770B;&#x5B98;&#x6307;&#x6B63;&#x3002;</p>
<p>#&#x7B80;&#x4ECB;</p>
<ul>
<li>&#x51C6;&#x5907;&#x6761;&#x4EF6;</li>
<li>Android Studio NDK&#x73AF;&#x5883;&#x642D;&#x5EFA;</li>
<li>Android Studio OpenCV&#x4F7F;&#x7528;</li>
<li>&#x5E38;&#x89C1;&#x95EE;&#x9898;</li>
</ul>
<p>##&#x51C6;&#x5907;&#x6761;&#x4EF6;</p>
<ul>
<li><p><a href="https://pan.baidu.com/s/1pMNObsZ" target="_blank" rel="noopener">openCV&#x538B;&#x7F29;&#x5305;&#x4E0B;&#x8F7D;</a>&#x5BC6;&#x7801;&#x3010;7xkh&#x3011;</p>
</li>
<li><p>Android Studio</p>
<h2 id="NDK&#x73AF;&#x5883;&#x642D;&#x5EFA;"><a href="#NDK&#x73AF;&#x5883;&#x642D;&#x5EFA;" class="headerlink" title="NDK&#x73AF;&#x5883;&#x642D;&#x5EFA;"></a>NDK&#x73AF;&#x5883;&#x642D;&#x5EFA;</h2><p>  &#x9996;&#x5148;&#xFF0C;&#x5728;Android Studio&#x4E2D;&#x6253;&#x5F00;File-&gt;setting-&gt;Android SDK-&gt;SDK Tools<br>&#x9009;&#x62E9;CMake&#x548C;NDK&#x7136;&#x540E;&#x70B9;&#x51FB;Apply&#x7B49;&#x5F85;&#x4E0B;&#x8F7D;&#x5B8C;&#x6210;&#x5373;&#x53EF;&#x3002;<br><img src="http://upload-images.jianshu.io/upload_images/1716569-f3db8a0991ccb129.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Android Studio Ndk&#x914D;&#x7F6E;.png"></p>
<ul>
<li><p>&#x9996;&#x5148;</p>
<p>  OpenCV&#x662F;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;BSD&#x8BB8;&#x53EF;&#xFF08;&#x5F00;&#x6E90;&#xFF09;&#x53D1;&#x884C;&#x7684;&#x8DE8;&#x5E73;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x89C6;&#x89C9;&#x5E93;&#xFF0C;&#x53EF;&#x4EE5;<br>&#x8FD0;&#x884C;&#x5728;Linux&#x3001;Windows&#x3001;Android&#x548C;Mac OS&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E0A;&#x3002;&#x5B83;&#x8F7B;&#x91CF;&#x7EA7;&#x800C;&#x4E14;<br>&#x9AD8;&#x6548;&#x2014;&#x2014;&#x7531;&#x4E00;&#x7CFB;&#x5217; C &#x51FD;&#x6570;&#x548C;&#x5C11;&#x91CF; C++ &#x7C7B;&#xFF0C;&#x540C;&#x65F6;&#x63D0;&#x4F9B;&#x4E86;Python&#x3001;Ruby&#x3001;<br>MATLAB&#x7B49;&#x8BED;&#x8A00;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x5B9E;&#x73B0;&#x4E86;&#x56FE;&#x50CF;&#x5904;&#x7406;&#x548C;&#x8BA1;&#x7B97;&#x673A;&#x89C6;&#x89C9;&#x65B9;&#x9762;&#x7684;&#x5F88;&#x591A;&#x901A;&#x7528;&#x7B97;&#x6CD5;&#x3002;<br>OpenCV&#x7528;C++&#x8BED;&#x8A00;&#x7F16;&#x5199;&#xFF0C;&#x5B83;&#x7684;&#x4E3B;&#x8981;&#x63A5;&#x53E3;&#x4E5F;&#x662F;C++&#x8BED;&#x8A00;&#xFF0C;&#x4F46;&#x662F;&#x4F9D;&#x7136;&#x4FDD;&#x7559;&#x4E86;&#x5927;&#x91CF;&#x7684;C&#x8BED;&#x8A00;&#x63A5;&#x53E3;&#x3002;<br>&#x8BE5;&#x5E93;&#x4E5F;&#x6709;&#x5927;&#x91CF;&#x7684;Python&#x3001;Java and MATLAB/OCTAVE&#xFF08;&#x7248;&#x672C;2.5&#xFF09;&#x7684;&#x63A5;&#x53E3;&#x3002;<br>&#x8FD9;&#x4E9B;&#x8BED;&#x8A00;&#x7684;API&#x63A5;&#x53E3;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5728;&#x7EBF;&#x6587;&#x6863;&#x83B7;&#x5F97;&#x3002;&#x5982;&#x4ECA;&#x4E5F;&#x63D0;&#x4F9B;&#x5BF9;&#x4E8E;C#&#x3001;Ch&#x3001;Ruby&#x7684;&#x652F;&#x6301;&#x3002;</p>
</li>
<li><p>&#x5176;&#x6B21;</p>
<p>  &#x5728;Android Studio&#x4E2D;&#x65B0;&#x5EFA;Project&#xFF0C;&#x9009;&#x4E2D;Include c++ support,&#x4E4B;&#x540E;&#x4E00;&#x76F4;&#x9ED8;&#x8BA4;&#x9009;&#x62E9;&#xFF0C;<br>&#x5728;C++&#x7248;&#x672C;&#x9009;&#x4E2D;c++11,&#x7136;&#x540E;finish&#x5B8C;&#x6210;&#x521B;&#x5EFA;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;<br><img src="http://upload-images.jianshu.io/upload_images/1716569-3f43cc05dac1b245.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Android Studio&#x521B;&#x5EFA;&#x5DE5;&#x7A0B;.png"></p>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>&#x7136;&#x540E;</p>
<pre><code>   &#x5BFC;&#x5165;OpenCV&#x4E2D;&#x7684;Java&#x5E93;&#xFF0C;&#x8FD9;&#x4E2A;&#x5E93;&#x662F;OpenCV-android-sdk ---&gt;sdk---&gt;java,&#x9009;&#x62E9;java&#x4E4B;&#x540E;&#x76F4;&#x63A5;&#x5BFC;&#x5165;&#x3002;
&#x4E4B;&#x540E;&#x70B9;&#x51FB;Android Studio&#x4E2D;&#x7684;Project Structure&#xFF0C;&#x6216;&#x8005;&#x76F4;&#x63A5;&#x6309;ctrl+alt+shift+s&#x6253;&#x5F00;&#x5E93;&#x4F9D;&#x8D56;&#x9762;&#x677F;&#xFF0C;
&#x9009;&#x62E9;moudle Dependency,&#x9009;&#x62E9;OpenCVLibrary330&#x6DFB;&#x52A0;&#x5373;&#x53EF;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</code></pre><p>   <img src="http://upload-images.jianshu.io/upload_images/1716569-eea5e8241e3995fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Android Studio &#x4F9D;&#x8D56;&#x9879;&#x76EE;.png"></p>
</li>
<li><p>&#x518D;&#x6B21;</p>
<pre><code>&#x5728;AS&#x4E2D;&#x6253;&#x5F00;CMakeLists.txt&#x8BBE;&#x7F6E;OpenCV&#x7684;&#x8DEF;&#x5F84;&#xFF08;&#x6B64;&#x8DEF;&#x5F84;&#x4E3A;&#x4F60;&#x672C;&#x5730;&#x7684;&#x8DEF;&#x5F84;&#xFF09;
# ##################### OpenCV &#x73AF;&#x5883; 

#&#x8BBE;&#x7F6E;OpenCV-android-sdk&#x8DEF;&#x5F84;
set( OpenCV_DIR E:/Source/OpenCV-android-sdk/sdk/native/jni )

find_package(OpenCV REQUIRED )
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS &quot;OpenCV library status:&quot;)
message(STATUS &quot;    version: ${OpenCV_VERSION}&quot;)
message(STATUS &quot;    libraries: ${OpenCV_LIBS}&quot;)
message(STATUS &quot;    include path: ${OpenCV_INCLUDE_DIRS}&quot;)
else(OpenCV_FOUND)
message(FATAL_ERROR &quot;OpenCV library not found&quot;)
endif(OpenCV_FOUND)</code></pre></li>
</ul>
<p><em>&#x6CE8;&#x610F;&#xFF1A;</em>  &#x4E0A;&#x9762;&#x7684;set&#xFF08; OpenCV_DIR E:/Source/OpenCV-android-sdk/sdk/native/jni&#xFF09;&#x628A;&#x6B64;&#x8DEF;&#x5F84;&#x6362;&#x6210;&#x4F60;&#x672C;&#x5730;&#x7684;&#x8DEF;&#x5F84;&#x3002;</p>
<ul>
<li><p>&#x6700;&#x540E;</p>
<pre><code> &#x5C06;OpenCV-android-sdk&#x4E0B;&#x9762;&#x7684;sdk--&gt;native--&gt;libs&#x4E0B;&#x9762;&#x7684;&#x6587;&#x4EF6;&#x590D;&#x5236;&#x5230;AS&#x4E2D;libs&#x8DEF;&#x5F84;&#x4E0B;&#x3002;
&#x7136;&#x540E;&#x5728;app &#x7684;build.gradle&#x7684;android&#x4E0B;&#x6DFB;&#x52A0;&#x5982;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;

task nativeLibsToJar(type: Jar, description: &apos;create a jar archive of the native libs&apos;) {
destinationDir file(&quot;$buildDir/native-libs&quot;)
baseName &apos;native-libs&apos;
 from fileTree(dir: &apos;libs&apos;, include: &apos;**/*.so&apos;)
into &apos;lib/&apos;
}

tasks.withType(JavaCompile) {</code></pre><p>   &#x200B;    compileTask -&gt; compileTask.dependsOn(nativeLibsToJar)</p>
<pre><code> }

&#x6700;&#x540E;&#x8FD8;&#x9700;&#x8981;&#x5728;dependencies&#x6DFB;&#x52A0; 

 implementation fileTree(dir: &quot;$buildDir/native-libs&quot;, include: &apos;native-libs.jar&apos;)</code></pre><p>   _&#x63D0;&#x793A; :_&#x5230;&#x8FD9;&#x91CC;OpenCV&#x7684;&#x73AF;&#x5883;&#x5DF2;&#x7ECF;&#x914D;&#x7F6E;&#x5B8C;&#x4E86;&#xFF0C;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x6765;&#x5199;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;DEMO&#x9A8C;&#x8BC1;&#x4E00;&#x4E0B;&#x3002;</p>
</li>
</ul>
<p>##&#x7B80;&#x5355;DEMO&#x9A8C;&#x8BC1;<br>_&#x6CE8;&#x610F; :_&#x672C;demo&#x53EA;&#x662F;&#x7B80;&#x5355;&#x9A8C;&#x8BC1;&#xFF0C;6.0&#x7684;&#x8FD0;&#x884C;&#x65F6;&#x6743;&#x9650;&#x7B49;&#x7B49;&#x6CA1;&#x6709;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#x3002;</p>
<ul>
<li><p>&#x65B0;&#x5EFA;MainActivity</p>
<pre><code>public class MainActivity extends AppCompatActivity implements 
 View.OnClickListener { 
 //&#x6700;&#x5927;</code></pre><p>  &#x200B;    private double max_size = 1024;<br>  &#x200B;    //&#x56DE;&#x8C03;</p>
<pre><code>private int PICK_IMAGE_REQUEST = 1;
//&#x539F;&#x56FE;&#x3001;&#x5904;&#x7406;&#x540E;&#x7684;&#x56FE;&#x7247;</code></pre><p>  &#x200B;     private ImageView mImgOriginal, mImgDeals;</p>
<pre><code>//&#x539F;&#x59CB;Bitmap&#x3001;&#x5904;&#x7406;&#x540E;&#x7684;Bitmap
private Bitmap mOriginalBitmap,mDealBitmap;
//&#x9009;&#x62E9;&#x56FE;&#x7247;&#x3001;&#x5904;&#x7406;</code></pre><p>  &#x200B;     private Button mBtnChoose, mBtnDeals;</p>
<pre><code> @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
onLoadOpenCVLibrary();</code></pre><p>  &#x200B;    initView();</p>
<pre><code> }

/**
 * &#x521D;&#x59CB;&#x5316;
      */
         private void initView() {
        mImgDeals = findViewById(R.id.img_deals);
        mImgOriginal = findViewById(R.id.img_original);
        mBtnChoose = findViewById(R.id.btn_choose);
        mBtnDeals = findViewById(R.id.btn_deals);

mBtnDeals.setOnClickListener(this);
mBtnChoose.setOnClickListener(this);

 }</code></pre></li>
</ul>
<pre><code> @Override
public void onClick(View view) {
switch (view.getId()) {
    case R.id.btn_choose: {//&#x9009;&#x62E9;
        selectImage();
        break;
    }
    case R.id.btn_deals: {//&#x5904;&#x7406;
        convertGray();
        break;
    }
}
}

  @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null
        &amp;&amp; data.getData() != null) {
    Uri uri = data.getData();
    try {
        Log.e(&quot;image-tag&quot;, &quot;start to decode selected image now...&quot;);
        InputStream input = getContentResolver().openInputStream(uri);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(input, null, options);
        int raw_width = options.outWidth;
        int raw_height = options.outHeight;
        int max = Math.max(raw_width, raw_height);
        int newWidth = raw_width;
        int newHeight = raw_height;
        int inSampleSize = 1;
        if (max &gt; max_size) {
            newWidth = raw_width / 2;
            newHeight = raw_height / 2;
            while ((newWidth / inSampleSize) &gt; max_size || (newHeight / inSampleSize) &gt; max_size) {
                inSampleSize *= 2;
            }
        }

        options.inSampleSize = inSampleSize;
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        mOriginalBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri),
                null, options);
        mDealBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri),
                null, options);
        mImgOriginal.setImageBitmap(mOriginalBitmap);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

/**
 * OpenCV&#x5E93;&#x9759;&#x6001;&#x52A0;&#x8F7D;&#x5E76;&#x521D;&#x59CB;&#x5316;
 */
 private void onLoadOpenCVLibrary() {
  boolean load = OpenCVLoader.initDebug();
  if (load) {
    Log.e(&quot;CV&quot;, &quot;Open CV Libraries loaded...&quot;);
   }
 }

 /**
  * &#x9009;&#x62E9;&#x56FE;&#x7247;
  */
private void selectImage() {
Intent intent = new Intent();
intent.setType(&quot;image/*&quot;);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, &quot;&#x9009;&#x62E9;&#x56FE;&#x50CF;&quot;), PICK_IMAGE_REQUEST);
 }

/**
 * &#x8F6C;&#x6362;
 */
 private void convertGray(){
Mat src = new Mat();
Mat temp = new Mat();
Mat dst = new Mat();
Utils.bitmapToMat(mDealBitmap, src);
Imgproc.cvtColor(src, temp, Imgproc.COLOR_BGRA2BGR);
Imgproc.cvtColor(temp, dst, Imgproc.COLOR_BGR2GRAY);
Utils.matToBitmap(dst, mDealBitmap);
mImgDeals.setImageBitmap(mDealBitmap);
 }
 }</code></pre><ul>
<li><p>&#x65B0;&#x5EFA;&#x8D44;&#x6E90;&#x6587;&#x4EF6;</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;vertical&quot;&gt;

&lt;LinearLayout
  android:layout_width=&quot;wrap_content&quot;
  android:layout_height=&quot;wrap_content&quot;
  android:orientation=&quot;horizontal&quot;&gt;

  &lt;Button
      android:id=&quot;@+id/btn_choose&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_margin=&quot;10dp&quot;
      android:text=&quot;@string/btn_choose&quot;
      android:textSize=&quot;16sp&quot; /&gt;

  &lt;Button
      android:id=&quot;@+id/btn_deals&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_margin=&quot;10dp&quot;
      android:text=&quot;@string/btn_deals&quot;
      android:textSize=&quot;16sp&quot; /&gt;

&lt;/LinearLayout&gt;

&lt;ImageView
  android:id=&quot;@+id/img_original&quot;
  android:layout_width=&quot;200dp&quot;
  android:layout_height=&quot;200dp&quot;
  android:layout_gravity=&quot;center&quot;
  android:layout_margin=&quot;16dp&quot;
  android:scaleType=&quot;fitCenter&quot;
  android:src=&quot;@mipmap/ic_launcher&quot; /&gt;

&lt;ImageView
  android:id=&quot;@+id/img_deals&quot;
  android:layout_width=&quot;200dp&quot;
  android:layout_height=&quot;200dp&quot;
  android:layout_gravity=&quot;center&quot;
  android:layout_margin=&quot;16dp&quot;
  android:scaleType=&quot;fitCenter&quot;
  android:src=&quot;@mipmap/ic_launcher&quot; /&gt;
&lt;/LinearLayout&gt;</code></pre></li>
<li><p>&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x7684;&#x6548;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;<br><img src="http://upload-images.jianshu.io/upload_images/1716569-1d4ceece061a91f2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="AS&#x8D44;&#x6E90;&#x6587;&#x4EF6;.png"></p>
</li>
<li><p>&#x6700;&#x7EC8;&#x8FD0;&#x884C;&#x7684;&#x6548;&#x679C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;<br><img src="http://upload-images.jianshu.io/upload_images/1716569-b43e1f03a33a4539.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="AS&#x6548;&#x679C;&#x56FE;.png"></p>
</li>
</ul>
<h1 id="&#x611F;&#x8A00;"><a href="#&#x611F;&#x8A00;" class="headerlink" title="&#x611F;&#x8A00;"></a>&#x611F;&#x8A00;</h1><ul>
<li>&#x7ECF;&#x8FC7;&#x4E24;&#x5929;&#x7684;&#x6298;&#x817E;&#xFF0C;&#x9047;&#x5230;&#x4E86;&#x5404;&#x79CD;Bug&#xFF0C;&#x7EC8;&#x4E8E;&#x641E;&#x5B9A;&#x7684;&#xFF0C;&#x9664;&#x4E86;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x6DFB;&#x52A0;OpenCV&#x4E4B;&#x5916;&#x8FD8;&#x6709;&#x6DFB;&#x52A0;.mk&#x6587;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;&#x7B49;&#x7B49;&#x3002;&#x8FD9;&#x91CC;&#x5C31;&#x4E0D;&#x591A;&#x505A;&#x4ECB;&#x7ECD;&#x4E86;&#xFF0C;&#x60F3;&#x4E86;&#x89E3;&#x7684;&#x770B;&#x5B98;&#x53EF;&#x4EE5;&#x53BB;&#x81EA;&#x884C;&#x641C;&#x7D22;&#x3002;</li>
<li>&#x611F;&#x8C22;gloomyfish&#x7684;<a href="http://blog.csdn.net/jia20003/article/details/53126321" target="_blank" rel="noopener">OpenCV On Android&#x5F00;&#x53D1; - Android Studio&#x4E0A;&#x73AF;&#x5883;&#x914D;&#x7F6E;</a><ul>
<li><a href="https://github.com/muyishuangfeng/OpenCV" target="_blank" rel="noopener">github&#x76EE;&#x5F55;</a></li>
<li><a href="https://muyishuangfeng.github.io" target="_blank" rel="noopener">&#x4E2A;&#x4EBA;&#x535A;&#x5BA2;&#x4E3B;&#x9875;</a></li>
</ul>
</li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/08/21/Android-socket高级用法（自定义协议和Protocol-Buffer使用）/" rel="next" title="Android socket高级用法（自定义协议和Protocol Buffer使用）">
                <i class="fa fa-chevron-left"></i> Android socket高级用法（自定义协议和Protocol Buffer使用）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/08/21/Android-TextView-点击超链接跳转实现/" rel="prev" title="Android TextView 点击超链接跳转实现">
                Android TextView 点击超链接跳转实现 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Silence潇湘夜雨</p>
              <p class="site-description motion-element" itemprop="description">Android开发一枚</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">55</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/muyishuangfeng" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/1e2eec6f972c" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/58df0abf61ff4b006b115e43" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-star"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/yangke20792452" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#NDK环境搭建"><span class="nav-number">2.</span> <span class="nav-text">NDK环境搭建</span></a></li></ol><li class="nav-item nav-level-1"><a class="nav-link" href="#感言"><span class="nav-number"></span> <span class="nav-text">感言</span></a></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Silence潇湘夜雨</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">114.8k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":false},"react":{"opacityDefault":0.5,"opacityOnHover":0.5},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
